#include <stdio.h>
#include <string.h>
#define SIZE_MAX 20
typedef struct String
{
    char str[SIZE_MAX];
    int length;
} S, *List;
int next[SIZE_MAX];
List addtion();
int index(List a, List b, int postion);
int main()
{
    int i;
    List a, b;
    a = addtion();
    b = addtion();
    get_next(b, next);
    printf("%d\n", index(a, b, 1));
    return 0;
}
List addtion()
{
    List l;
    int i, n;
    l = (List)malloc(sizeof(S));
    scanf("%d", &n);
    l->length = n;
    getchar();
    for(i=1; i<=n; i++)
    {
        scanf("%c", &l->str[i]);
    }
    return l;
}
void get_next(List l,int next[])
{
    int i=1, j=0;
    next[1]=0;
    while(i<=l->length)
    {
        if(l->str[i]==l->str[j]||j==0)
        {
            ++i;
            ++j;
            if(l->str[i]!=l->str[j])
                next[i] = j;
            else
                next[i] = next[j];
        }
        else
        {
            j = next[j];
        }
    }
}
int index(List a, List b, int postion)
{
    int i=postion,j=1;
    while(i<=a->length&&j<=b->length)
    {
        if(a->str[i]==b->str[j])
        {
            ++i,++j;
        }
        else
        j = next[j];
        if(j>b->length)
        {
            return i-j+1;
        }
        if(j == 0){
            i++;
            j=1;
        }
    }
    return 0;
}
